package com.quantdo.action;

import java.sql.SQLException;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

import com.quantdo.pojo.ServerDto;
import com.quantdo.service.ServerManageService;
import com.quantdo.ui.TomcatManageUiPart;

public class TmAddAction extends MouseAdapter{
	private ServerManageService manageService;// =  new ServerManageService();
	private TomcatManageUiPart manageUiPart;
	public TmAddAction(TomcatManageUiPart manageUiPart) {
		this.manageUiPart = manageUiPart;
	}

	@Override
	public void mouseUp(MouseEvent e) {
		manageService =  new ServerManageService();
		manageUiPart.getServerlist().add("server-ip");
		manageUiPart.getServerlist().setData("fdsafdsaf", new Object());
		ServerDto serverDto = new ServerDto();
		serverDto.setServerAddr(manageUiPart.getServerip().getText());
		serverDto.setUserName(manageUiPart.getUsername().getText());
		serverDto.setPassword(manageUiPart.getPassword().getText());
		try {
			manageService.save(serverDto);
			manageUiPart.getConsoleLog().append(String.format("添加成功:%s, %s", serverDto.getServerAddr(), serverDto.getUserName()));
		} catch (SQLException e1) {
			manageUiPart.getConsoleLog().append(String.format("添加失败:%s, %s", serverDto.getServerAddr(), serverDto.getUserName()));
		}
		super.mouseUp(e);
	}


}
